// pages/myself/mydown.js
var util = require('../../utils/util.js');
const app = getApp()
var page = 1;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        listInfo: [],
        imgUrls: [],
        dataSource: [],
        loading: true,
        level:1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        page = 1;
        if (options.lvl){
            this.setData({
                level: options.lvl
            })
        }
    },

    //滚动到底部刷新
    onReachBottom: function () {
        this.getMydowns();
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        page = 1;
        this.setData({
            dataSource: [],
            listInfo: app.globalData.listInfo
        })
        this.getMydowns();
    },

    //获取企业信息
    getMydowns: function () {
        var that = this;
        var limit = 10;
        wx.request({
            url: app.globalData.hostUrl + 'member/mydownline',
            data: {
                page: page,
                limit: limit,
                lvl:that.data.level,
                uid:wx.getStorageSync('userId')            
            },
            methods: 'GET',
            header: {
                "Content-Type": "json"
            },
            success: function (res) {
                //console.log(res);
                if (res.data.result) {
                    page++
                    that.setData({
                        dataSource: that.data.dataSource.concat(res.data.result)
                    });
                    if (res.data.result.length < limit) {
                        that.setData({
                            loading: false
                        })
                    }
                }
                else {
                    that.setData({
                        loading: false
                    })
                    return false
                }
            }
        })
    },
  gotolvl1:function(){
     wx.redirectTo({
       url: '../myself/mydown?lvl=1',
     })
  },
  gotolvl2: function () {
    wx.redirectTo({
      url: '../myself/mydown?lvl=2',
    })
  },
  gohome: function () {
    wx.redirectTo({
      url: '../index/index',
    })
  },
  yuy: function () {
    if (1 == wx.getStorageSync('roleidentity')) {
      wx.redirectTo({
        url: '../myself/thappointment',
      })
    }
    else {
      wx.redirectTo({
        url: '../myself/myappointment',
      })
    }
  },
  orders: function () {
    if (1 == wx.getStorageSync('roleidentity')) {
      wx.redirectTo({
        url: '../myself/trorder',
      })
    }
    else {
      wx.redirectTo({
        url: '../myself/myorder',
      })
    }
  },
  mys: function () {
    wx.redirectTo({
      url: '../myself/myself',
    })
  },
    onShareAppMessage: function () {

    }
})